package com.klhappy.houyuan.dialog;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.klhappy.houyuan.activity.ConfirmMoneyActivity;
import com.klhappy.houyuan.activity.LoginActivity;
import com.klhappy.houyuan.R;
import com.klhappy.houyuan.utils.NotifyMethod;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by MrPu on 15/11/28.
 */
public class NetWorkDialog {
    @InjectView(R.id.msg_tv) TextView msg_tv;

    private Dialog dialog;
    private Context context;
    private String msg;

    @OnClick(R.id.yes_tv)
    public void yes_tv(){
        if (msg.equals("请登录")){
            context.startActivity(new Intent(context , LoginActivity.class));
        }
        Dismiss();
    }
    @OnClick(R.id.close)
    public void close(){
        Dismiss();
        NotifyMethod.getInstance().postNotification(ConfirmMoneyActivity.AVG);
    }

    public NetWorkDialog(Context context) {
        this.context = context;
    }

    public void netWork(String msg){
        this.msg = msg;
        View view = LayoutInflater.from(context).inflate(R.layout.net_work_dialog ,null);
        ButterKnife.inject(this ,view);
        msg_tv.setText(msg);

        dialog = new Dialog(context ,R.style.Dialog_Fullscreen);
        dialog.setContentView(view);
        if (dialog.isShowing()){
            dialog.dismiss();
        }else {
            dialog.show();
        }
    }

    public void show(){
        dialog.show();
    }

    public void Dismiss(){
        if (dialog.isShowing()){
            dialog.dismiss();
        }
    }
}
